from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore

import sys
import t_close_main_windowrcc_rc

class WindowDemo(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(WindowDemo, self).__init__(parent)

        label1 = QtWidgets.QLabel(self)
        label2 = QtWidgets.QLabel(self)
        label3 = QtWidgets.QLabel(self)
        label4 = QtWidgets.QLabel(self)


        # init label1
        label1.setText("这是一个文本标签.")

        label1.setAutoFillBackground(True)

        palette = QtGui.QPalette()
        palette.setColor(QtGui.QPalette.Window, QtCore.Qt.blue)
        label1.setPalette(palette)

        label1.setAlignment(QtCore.Qt.AlignCenter)

        label1.setOpenExternalLinks(True)
        label1.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)

        # init label2
        label2.setText("<a href='#'>欢迎使用Python GUI 应用</a>")
        label2.linkHovered.connect(self.link_hovered)


        # init label3
        label3.setAlignment(QtCore.Qt.AlignCenter)
        label3.setToolTip("这是一个图片标签")
        label3.setPixmap(QtGui.QPixmap(":/pic/python.jpg"))


        # init label4
        label4.setText("<a href='https://www.baidu.com/'>欢迎使用百度</a>")
        label4.setAlignment(QtCore.Qt.AlignCenter)
        label4.setToolTip("这是一个超链接")
        label4.linkActivated.connect(self.link_clicked)


        # 布局
        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(label1)
        vbox.addStretch()
        vbox.addWidget(label2)
        vbox.addStretch()
        vbox.addWidget(label3)
        vbox.addStretch()
        vbox.addWidget(label4)

        self.setLayout(vbox)
        self.setWindowTitle("QLabel demo")

    def link_hovered(self):
        print("label2 link_hovered")

    def link_clicked(self):
        print("label4 link clicked")


class BuddyDemo(QtWidgets.QDialog):
    def __init__(self):
        super(BuddyDemo, self).__init__()

        self.setWindowTitle("qlabel buddy 例子")

        nameLb1 = QtWidgets.QLabel("&Name", self)
        nameEd1 = QtWidgets.QLineEdit(self)
        nameLb1.setBuddy(nameEd1)

        pswLb2  = QtWidgets.QLabel("&Password", self)
        pswEd2  = QtWidgets.QLineEdit(self)
        pswLb2.setBuddy(pswEd2)

        btnOk   = QtWidgets.QPushButton("&OK")
        btnCancel = QtWidgets.QPushButton("&Cancel")

        mainLayout = QtWidgets.QGridLayout(self)
        mainLayout.addWidget(nameLb1, 0, 0)
        mainLayout.addWidget(nameEd1, 0, 1, 1, 2)
        mainLayout.addWidget(pswLb2, 1, 0)
        mainLayout.addWidget(pswEd2, 1, 1, 1, 2)

        mainLayout.addWidget(btnOk, 2, 1)
        mainLayout.addWidget(btnCancel, 2, 2)




if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    win = BuddyDemo()
    win.show()
    sys.exit(app.exec_())




